﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HOBA.SMSSender
{
    public partial class SendSMS : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString.Count > 0 && Request.QueryString["message"] != "")
            {
                lblMessage.Visible = true;
                lblMessage.Text = Request.QueryString["message"];
            }
            else
            {
                lblMessage.Visible = false;
                lblMessage.Text = "";
            }
        }

        protected void Submit(object sender, EventArgs e)
        {
            System.Security.Cryptography.MD5 md5hasher = System.Security.Cryptography.MD5.Create();
            Random rnum = new Random();
            byte[] input = new byte[16];
            rnum.NextBytes(input);
            byte[] data = md5hasher.ComputeHash(input);
            Guid smsguid = new Guid(data);

            try
            {
                MySoapService service = new MySoapService("http://center.fibosms.com/Service.asmx");
                string response = service.SendSMS(Session["username"].ToString(), Session["password"].ToString()
                        , txtReceiver.Text, txtContent.Text, smsguid.ToString(), "1357");
                String code, message, time;
                FileUtility.ReadFiboSentStatus(response, out code, out message, out time);

                message = HttpUtility.UrlEncode(message);
                Response.Redirect("SendSMS.aspx?message=" + message + " " + Session["username"].ToString() + " " + Session["password"].ToString());
            }
            catch (Exception exc)
            {
            }
        }
    }
}
